package com.luca.framework.handle;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.luca.common.utils.SecurityUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 自定义字段填充
 *
 * @author luca
 */
@Slf4j
@Component
public class CustomerMetaObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        this.strictInsertFill(metaObject, "createBy", String.class, SecurityUtils.getUsername());
        this.strictInsertFill(metaObject, "createTime", Date.class, new Date());
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("updateBy", SecurityUtils.getUsername(), metaObject);
        this.setFieldValByName("updateTime", new Date(), metaObject);
    }
}
